package shop.up.product.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import shop.up.common.result.Result;
import shop.up.model.product.BaseTrademark;
import shop.up.product.service.BaseTrademarkService;

import javax.annotation.Resource;
import java.util.List;

/**
 * 品牌管理 {@link BaseTrademarkController}
 *
 * @author Kevin
 * @date 2023/3/29
 */
@Api(tags = "品牌管理接口")
@RequestMapping("admin/product/baseTrademark")
@RestController
public class BaseTrademarkController {

    @Resource
    private BaseTrademarkService baseTrademarkService;

    /**
     * 查询全部品牌
     * @return
     */
    @GetMapping("getTrademarkList")
    public Result<List<BaseTrademark>> getTrademarkList() {
        List<BaseTrademark> trademarkList = baseTrademarkService.list(null);
        return Result.ok(trademarkList);
    }

    /**
     * 品牌列表查询
     * @return
     */
    @ApiOperation("分页列表")
    @GetMapping("/{page}/{limit}")
    public Result<IPage<BaseTrademark>> getPage(@PathVariable("page") Long page,
                                               @PathVariable("limit") Long limit) {
        Page<BaseTrademark> baseTrademarkPage = new Page<>(page, limit);
        IPage<BaseTrademark> baseTrademarkIPage = baseTrademarkService.page(baseTrademarkPage, null);
        return Result.ok(baseTrademarkIPage);
    }

    @ApiOperation(value = "获取品牌")
    @GetMapping("get/{id}")
    public Result<BaseTrademark> get(@PathVariable String id) {
        BaseTrademark baseTrademark = baseTrademarkService.getById(id);
        return Result.ok(baseTrademark);
    }

    @ApiOperation(value = "新增品牌")
    @PostMapping("save")
    public Result save(@RequestBody BaseTrademark banner) {
        baseTrademarkService.save(banner);
        return Result.ok();
    }

    @ApiOperation(value = "修改品牌")
    @PutMapping("update")
    public Result updateById(@RequestBody BaseTrademark banner) {
        baseTrademarkService.updateById(banner);
        return Result.ok();
    }

    @ApiOperation(value = "删除品牌")
    @DeleteMapping("remove/{id}")
    public Result remove(@PathVariable Long id) {
        baseTrademarkService.removeById(id);
        return Result.ok();
    }

}
